| Conditions | 3 |
| Paths | 8 |
| Total Lines | 519 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 609 | THREE.TransformControls = function ( camera, domElement ) { |
||
| 610 | |||
| 611 | // TODO: Make non-uniform scale and rotate play nice in hierarchies |
||
| 612 | // TODO: ADD RXYZ contol |
||
| 613 | |||
| 614 | THREE.Object3D.call( this ); |
||
| 615 | |||
| 616 | domElement = ( domElement !== undefined ) ? domElement : document; |
||
| 617 | |||
| 618 | this.object = undefined; |
||
| 619 | this.visible = false; |
||
| 620 | this.translationSnap = null; |
||
| 621 | this.rotationSnap = null; |
||
| 622 | this.space = "world"; |
||
| 623 | this.size = 1; |
||
| 624 | this.axis = null; |
||
| 625 | |||
| 626 | var scope = this; |
||
| 627 | |||
| 628 | var _mode = "translate"; |
||
| 629 | var _dragging = false; |
||
| 630 | var _plane = "XY"; |
||
| 631 | var _gizmo = { |
||
| 632 | |||
| 633 | "translate": new THREE.TransformGizmoTranslate(), |
||
| 634 | "rotate": new THREE.TransformGizmoRotate(), |
||
| 635 | "scale": new THREE.TransformGizmoScale() |
||
| 636 | }; |
||
| 637 | |||
| 638 | for ( var type in _gizmo ) { |
||
| 639 | |||
| 640 | var gizmoObj = _gizmo[ type ]; |
||
| 641 | |||
| 642 | gizmoObj.visible = ( type === _mode ); |
||
| 643 | this.add( gizmoObj ); |
||
| 644 | |||
| 645 | } |
||
| 646 | |||
| 647 | var changeEvent = { type: "change" }; |
||
| 648 | var mouseDownEvent = { type: "mouseDown" }; |
||
| 649 | var mouseUpEvent = { type: "mouseUp", mode: _mode }; |
||
| 650 | var objectChangeEvent = { type: "objectChange" }; |
||
| 651 | |||
| 652 | var ray = new THREE.Raycaster(); |
||
| 653 | var pointerVector = new THREE.Vector2(); |
||
| 654 | |||
| 655 | var point = new THREE.Vector3(); |
||
| 656 | var offset = new THREE.Vector3(); |
||
| 657 | |||
| 658 | var rotation = new THREE.Vector3(); |
||
| 659 | var offsetRotation = new THREE.Vector3(); |
||
| 660 | var scale = 1; |
||
| 661 | |||
| 662 | var lookAtMatrix = new THREE.Matrix4(); |
||
| 663 | var eye = new THREE.Vector3(); |
||
| 664 | |||
| 665 | var tempMatrix = new THREE.Matrix4(); |
||
| 666 | var tempVector = new THREE.Vector3(); |
||
| 667 | var tempQuaternion = new THREE.Quaternion(); |
||
| 668 | var unitX = new THREE.Vector3( 1, 0, 0 ); |
||
| 669 | var unitY = new THREE.Vector3( 0, 1, 0 ); |
||
| 670 | var unitZ = new THREE.Vector3( 0, 0, 1 ); |
||
| 671 | |||
| 672 | var quaternionXYZ = new THREE.Quaternion(); |
||
| 673 | var quaternionX = new THREE.Quaternion(); |
||
| 674 | var quaternionY = new THREE.Quaternion(); |
||
| 675 | var quaternionZ = new THREE.Quaternion(); |
||
| 676 | var quaternionE = new THREE.Quaternion(); |
||
| 677 | |||
| 678 | var oldPosition = new THREE.Vector3(); |
||
| 679 | var oldScale = new THREE.Vector3(); |
||
| 680 | var oldRotationMatrix = new THREE.Matrix4(); |
||
| 681 | |||
| 682 | var parentRotationMatrix = new THREE.Matrix4(); |
||
| 683 | var parentScale = new THREE.Vector3(); |
||
| 684 | |||
| 685 | var worldPosition = new THREE.Vector3(); |
||
| 686 | var worldRotation = new THREE.Euler(); |
||
| 687 | var worldRotationMatrix = new THREE.Matrix4(); |
||
| 688 | var camPosition = new THREE.Vector3(); |
||
| 689 | var camRotation = new THREE.Euler(); |
||
| 690 | |||
| 691 | domElement.addEventListener( "mousedown", onPointerDown, false ); |
||
| 692 | domElement.addEventListener( "touchstart", onPointerDown, false ); |
||
| 693 | |||
| 694 | domElement.addEventListener( "mousemove", onPointerHover, false ); |
||
| 695 | domElement.addEventListener( "touchmove", onPointerHover, false ); |
||
| 696 | |||
| 697 | domElement.addEventListener( "mousemove", onPointerMove, false ); |
||
| 698 | domElement.addEventListener( "touchmove", onPointerMove, false ); |
||
| 699 | |||
| 700 | domElement.addEventListener( "mouseup", onPointerUp, false ); |
||
| 701 | domElement.addEventListener( "mouseout", onPointerUp, false ); |
||
| 702 | domElement.addEventListener( "touchend", onPointerUp, false ); |
||
| 703 | domElement.addEventListener( "touchcancel", onPointerUp, false ); |
||
| 704 | domElement.addEventListener( "touchleave", onPointerUp, false ); |
||
| 705 | |||
| 706 | this.dispose = function () { |
||
| 707 | |||
| 708 | domElement.removeEventListener( "mousedown", onPointerDown ); |
||
| 709 | domElement.removeEventListener( "touchstart", onPointerDown ); |
||
| 710 | |||
| 711 | domElement.removeEventListener( "mousemove", onPointerHover ); |
||
| 712 | domElement.removeEventListener( "touchmove", onPointerHover ); |
||
| 713 | |||
| 714 | domElement.removeEventListener( "mousemove", onPointerMove ); |
||
| 715 | domElement.removeEventListener( "touchmove", onPointerMove ); |
||
| 716 | |||
| 717 | domElement.removeEventListener( "mouseup", onPointerUp ); |
||
| 718 | domElement.removeEventListener( "mouseout", onPointerUp ); |
||
| 719 | domElement.removeEventListener( "touchend", onPointerUp ); |
||
| 720 | domElement.removeEventListener( "touchcancel", onPointerUp ); |
||
| 721 | domElement.removeEventListener( "touchleave", onPointerUp ); |
||
| 722 | |||
| 723 | }; |
||
| 724 | |||
| 725 | this.attach = function ( object ) { |
||
| 726 | |||
| 727 | this.object = object; |
||
| 728 | this.visible = true; |
||
| 729 | this.update(); |
||
| 730 | |||
| 731 | }; |
||
| 732 | |||
| 733 | this.detach = function () { |
||
| 734 | |||
| 735 | this.object = undefined; |
||
| 736 | this.visible = false; |
||
| 737 | this.axis = null; |
||
| 738 | |||
| 739 | }; |
||
| 740 | |||
| 741 | this.setMode = function ( mode ) { |
||
| 742 | |||
| 743 | _mode = mode ? mode : _mode; |
||
| 744 | |||
| 745 | if ( _mode === "scale" ) scope.space = "local"; |
||
| 746 | |||
| 747 | for ( var type in _gizmo ) _gizmo[ type ].visible = ( type === _mode ); |
||
| 748 | |||
| 749 | this.update(); |
||
| 750 | scope.dispatchEvent( changeEvent ); |
||
| 751 | |||
| 752 | }; |
||
| 753 | |||
| 754 | this.setTranslationSnap = function ( translationSnap ) { |
||
| 755 | |||
| 756 | scope.translationSnap = translationSnap; |
||
| 757 | |||
| 758 | }; |
||
| 759 | |||
| 760 | this.setRotationSnap = function ( rotationSnap ) { |
||
| 761 | |||
| 762 | scope.rotationSnap = rotationSnap; |
||
| 763 | |||
| 764 | }; |
||
| 765 | |||
| 766 | this.setSize = function ( size ) { |
||
| 767 | |||
| 768 | scope.size = size; |
||
| 769 | this.update(); |
||
| 770 | scope.dispatchEvent( changeEvent ); |
||
| 771 | |||
| 772 | }; |
||
| 773 | |||
| 774 | this.setSpace = function ( space ) { |
||
| 775 | |||
| 776 | scope.space = space; |
||
| 777 | this.update(); |
||
| 778 | scope.dispatchEvent( changeEvent ); |
||
| 779 | |||
| 780 | }; |
||
| 781 | |||
| 782 | this.update = function () { |
||
| 783 | |||
| 784 | if ( scope.object === undefined ) return; |
||
| 785 | |||
| 786 | scope.object.updateMatrixWorld(); |
||
| 787 | worldPosition.setFromMatrixPosition( scope.object.matrixWorld ); |
||
| 788 | worldRotation.setFromRotationMatrix( tempMatrix.extractRotation( scope.object.matrixWorld ) ); |
||
| 789 | |||
| 790 | camera.updateMatrixWorld(); |
||
| 791 | camPosition.setFromMatrixPosition( camera.matrixWorld ); |
||
| 792 | camRotation.setFromRotationMatrix( tempMatrix.extractRotation( camera.matrixWorld ) ); |
||
| 793 | |||
| 794 | scale = worldPosition.distanceTo( camPosition ) / 6 * scope.size; |
||
| 795 | this.position.copy( worldPosition ); |
||
| 796 | this.scale.set( scale, scale, scale ); |
||
| 797 | |||
| 798 | eye.copy( camPosition ).sub( worldPosition ).normalize(); |
||
| 799 | |||
| 800 | if ( scope.space === "local" ) { |
||
| 801 | |||
| 802 | _gizmo[ _mode ].update( worldRotation, eye ); |
||
| 803 | |||
| 804 | } else if ( scope.space === "world" ) { |
||
| 805 | |||
| 806 | _gizmo[ _mode ].update( new THREE.Euler(), eye ); |
||
| 807 | |||
| 808 | } |
||
| 809 | |||
| 810 | _gizmo[ _mode ].highlight( scope.axis ); |
||
| 811 | |||
| 812 | }; |
||
| 813 | |||
| 814 | function onPointerHover( event ) { |
||
| 815 | |||
| 816 | if ( scope.object === undefined || _dragging === true || ( event.button !== undefined && event.button !== 0 ) ) return; |
||
| 817 | |||
| 818 | var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event; |
||
| 819 | |||
| 820 | var intersect = intersectObjects( pointer, _gizmo[ _mode ].pickers.children ); |
||
| 821 | |||
| 822 | var axis = null; |
||
| 823 | |||
| 824 | if ( intersect ) { |
||
| 825 | |||
| 826 | axis = intersect.object.name; |
||
| 827 | |||
| 828 | event.preventDefault(); |
||
| 829 | |||
| 830 | } |
||
| 831 | |||
| 832 | if ( scope.axis !== axis ) { |
||
| 833 | |||
| 834 | scope.axis = axis; |
||
| 835 | scope.update(); |
||
| 836 | scope.dispatchEvent( changeEvent ); |
||
| 837 | |||
| 838 | } |
||
| 839 | |||
| 840 | } |
||
| 841 | |||
| 842 | function onPointerDown( event ) { |
||
| 843 | |||
| 844 | if ( scope.object === undefined || _dragging === true || ( event.button !== undefined && event.button !== 0 ) ) return; |
||
| 845 | |||
| 846 | var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event; |
||
| 847 | |||
| 848 | if ( pointer.button === 0 || pointer.button === undefined ) { |
||
| 849 | |||
| 850 | var intersect = intersectObjects( pointer, _gizmo[ _mode ].pickers.children ); |
||
| 851 | |||
| 852 | if ( intersect ) { |
||
| 853 | |||
| 854 | event.preventDefault(); |
||
| 855 | event.stopPropagation(); |
||
| 856 | |||
| 857 | scope.dispatchEvent( mouseDownEvent ); |
||
| 858 | |||
| 859 | scope.axis = intersect.object.name; |
||
| 860 | |||
| 861 | scope.update(); |
||
| 862 | |||
| 863 | eye.copy( camPosition ).sub( worldPosition ).normalize(); |
||
| 864 | |||
| 865 | _gizmo[ _mode ].setActivePlane( scope.axis, eye ); |
||
| 866 | |||
| 867 | var planeIntersect = intersectObjects( pointer, [ _gizmo[ _mode ].activePlane ] ); |
||
| 868 | |||
| 869 | if ( planeIntersect ) { |
||
| 870 | |||
| 871 | oldPosition.copy( scope.object.position ); |
||
| 872 | oldScale.copy( scope.object.scale ); |
||
| 873 | |||
| 874 | oldRotationMatrix.extractRotation( scope.object.matrix ); |
||
| 875 | worldRotationMatrix.extractRotation( scope.object.matrixWorld ); |
||
| 876 | |||
| 877 | parentRotationMatrix.extractRotation( scope.object.parent.matrixWorld ); |
||
| 878 | parentScale.setFromMatrixScale( tempMatrix.getInverse( scope.object.parent.matrixWorld ) ); |
||
| 879 | |||
| 880 | offset.copy( planeIntersect.point ); |
||
| 881 | |||
| 882 | } |
||
| 883 | |||
| 884 | } |
||
| 885 | |||
| 886 | } |
||
| 887 | |||
| 888 | _dragging = true; |
||
| 889 | |||
| 890 | } |
||
| 891 | |||
| 892 | function onPointerMove( event ) { |
||
| 893 | |||
| 894 | if ( scope.object === undefined || scope.axis === null || _dragging === false || ( event.button !== undefined && event.button !== 0 ) ) return; |
||
| 895 | |||
| 896 | var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event; |
||
| 897 | |||
| 898 | var planeIntersect = intersectObjects( pointer, [ _gizmo[ _mode ].activePlane ] ); |
||
| 899 | |||
| 900 | if ( planeIntersect === false ) return; |
||
| 901 | |||
| 902 | event.preventDefault(); |
||
| 903 | event.stopPropagation(); |
||
| 904 | |||
| 905 | point.copy( planeIntersect.point ); |
||
| 906 | |||
| 907 | if ( _mode === "translate" ) { |
||
| 908 | |||
| 909 | point.sub( offset ); |
||
| 910 | point.multiply( parentScale ); |
||
| 911 | |||
| 912 | if ( scope.space === "local" ) { |
||
| 913 | |||
| 914 | point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) ); |
||
| 915 | |||
| 916 | if ( scope.axis.search( "X" ) === - 1 ) point.x = 0; |
||
| 917 | if ( scope.axis.search( "Y" ) === - 1 ) point.y = 0; |
||
| 918 | if ( scope.axis.search( "Z" ) === - 1 ) point.z = 0; |
||
| 919 | |||
| 920 | point.applyMatrix4( oldRotationMatrix ); |
||
| 921 | |||
| 922 | scope.object.position.copy( oldPosition ); |
||
| 923 | scope.object.position.add( point ); |
||
| 924 | |||
| 925 | } |
||
| 926 | |||
| 927 | if ( scope.space === "world" || scope.axis.search( "XYZ" ) !== - 1 ) { |
||
| 928 | |||
| 929 | if ( scope.axis.search( "X" ) === - 1 ) point.x = 0; |
||
| 930 | if ( scope.axis.search( "Y" ) === - 1 ) point.y = 0; |
||
| 931 | if ( scope.axis.search( "Z" ) === - 1 ) point.z = 0; |
||
| 932 | |||
| 933 | point.applyMatrix4( tempMatrix.getInverse( parentRotationMatrix ) ); |
||
| 934 | |||
| 935 | scope.object.position.copy( oldPosition ); |
||
| 936 | scope.object.position.add( point ); |
||
| 937 | |||
| 938 | } |
||
| 939 | |||
| 940 | if ( scope.translationSnap !== null ) { |
||
| 941 | |||
| 942 | if ( scope.space === "local" ) { |
||
| 943 | |||
| 944 | scope.object.position.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) ); |
||
| 945 | |||
| 946 | } |
||
| 947 | |||
| 948 | if ( scope.axis.search( "X" ) !== - 1 ) scope.object.position.x = Math.round( scope.object.position.x / scope.translationSnap ) * scope.translationSnap; |
||
| 949 | if ( scope.axis.search( "Y" ) !== - 1 ) scope.object.position.y = Math.round( scope.object.position.y / scope.translationSnap ) * scope.translationSnap; |
||
| 950 | if ( scope.axis.search( "Z" ) !== - 1 ) scope.object.position.z = Math.round( scope.object.position.z / scope.translationSnap ) * scope.translationSnap; |
||
| 951 | |||
| 952 | if ( scope.space === "local" ) { |
||
| 953 | |||
| 954 | scope.object.position.applyMatrix4( worldRotationMatrix ); |
||
| 955 | |||
| 956 | } |
||
| 957 | |||
| 958 | } |
||
| 959 | |||
| 960 | } else if ( _mode === "scale" ) { |
||
| 961 | |||
| 962 | point.sub( offset ); |
||
| 963 | point.multiply( parentScale ); |
||
| 964 | |||
| 965 | if ( scope.space === "local" ) { |
||
| 966 | |||
| 967 | if ( scope.axis === "XYZ" ) { |
||
| 968 | |||
| 969 | scale = 1 + ( ( point.y ) / 50 ); |
||
| 970 | |||
| 971 | scope.object.scale.x = oldScale.x * scale; |
||
| 972 | scope.object.scale.y = oldScale.y * scale; |
||
| 973 | scope.object.scale.z = oldScale.z * scale; |
||
| 974 | |||
| 975 | } else { |
||
| 976 | |||
| 977 | point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) ); |
||
| 978 | |||
| 979 | if ( scope.axis === "X" ) scope.object.scale.x = oldScale.x * ( 1 + point.x / 50 ); |
||
| 980 | if ( scope.axis === "Y" ) scope.object.scale.y = oldScale.y * ( 1 + point.y / 50 ); |
||
| 981 | if ( scope.axis === "Z" ) scope.object.scale.z = oldScale.z * ( 1 + point.z / 50 ); |
||
| 982 | |||
| 983 | } |
||
| 984 | |||
| 985 | } |
||
| 986 | |||
| 987 | } else if ( _mode === "rotate" ) { |
||
| 988 | |||
| 989 | point.sub( worldPosition ); |
||
| 990 | point.multiply( parentScale ); |
||
| 991 | tempVector.copy( offset ).sub( worldPosition ); |
||
| 992 | tempVector.multiply( parentScale ); |
||
| 993 | |||
| 994 | if ( scope.axis === "E" ) { |
||
| 995 | |||
| 996 | point.applyMatrix4( tempMatrix.getInverse( lookAtMatrix ) ); |
||
| 997 | tempVector.applyMatrix4( tempMatrix.getInverse( lookAtMatrix ) ); |
||
| 998 | |||
| 999 | rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) ); |
||
| 1000 | offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) ); |
||
| 1001 | |||
| 1002 | tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) ); |
||
| 1003 | |||
| 1004 | quaternionE.setFromAxisAngle( eye, rotation.z - offsetRotation.z ); |
||
| 1005 | quaternionXYZ.setFromRotationMatrix( worldRotationMatrix ); |
||
| 1006 | |||
| 1007 | tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionE ); |
||
| 1008 | tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ ); |
||
| 1009 | |||
| 1010 | scope.object.quaternion.copy( tempQuaternion ); |
||
| 1011 | |||
| 1012 | } else if ( scope.axis === "XYZE" ) { |
||
| 1013 | |||
| 1014 | quaternionE.setFromEuler( point.clone().cross( tempVector ).normalize() ); // rotation axis |
||
| 1015 | |||
| 1016 | tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) ); |
||
| 1017 | quaternionX.setFromAxisAngle( quaternionE, - point.clone().angleTo( tempVector ) ); |
||
| 1018 | quaternionXYZ.setFromRotationMatrix( worldRotationMatrix ); |
||
| 1019 | |||
| 1020 | tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX ); |
||
| 1021 | tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ ); |
||
| 1022 | |||
| 1023 | scope.object.quaternion.copy( tempQuaternion ); |
||
| 1024 | |||
| 1025 | } else if ( scope.space === "local" ) { |
||
| 1026 | |||
| 1027 | point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) ); |
||
| 1028 | |||
| 1029 | tempVector.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) ); |
||
| 1030 | |||
| 1031 | rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) ); |
||
| 1032 | offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) ); |
||
| 1033 | |||
| 1034 | quaternionXYZ.setFromRotationMatrix( oldRotationMatrix ); |
||
| 1035 | |||
| 1036 | if ( scope.rotationSnap !== null ) { |
||
| 1037 | |||
| 1038 | quaternionX.setFromAxisAngle( unitX, Math.round( ( rotation.x - offsetRotation.x ) / scope.rotationSnap ) * scope.rotationSnap ); |
||
| 1039 | quaternionY.setFromAxisAngle( unitY, Math.round( ( rotation.y - offsetRotation.y ) / scope.rotationSnap ) * scope.rotationSnap ); |
||
| 1040 | quaternionZ.setFromAxisAngle( unitZ, Math.round( ( rotation.z - offsetRotation.z ) / scope.rotationSnap ) * scope.rotationSnap ); |
||
| 1041 | |||
| 1042 | } else { |
||
| 1043 | |||
| 1044 | quaternionX.setFromAxisAngle( unitX, rotation.x - offsetRotation.x ); |
||
| 1045 | quaternionY.setFromAxisAngle( unitY, rotation.y - offsetRotation.y ); |
||
| 1046 | quaternionZ.setFromAxisAngle( unitZ, rotation.z - offsetRotation.z ); |
||
| 1047 | |||
| 1048 | } |
||
| 1049 | |||
| 1050 | if ( scope.axis === "X" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionX ); |
||
| 1051 | if ( scope.axis === "Y" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionY ); |
||
| 1052 | if ( scope.axis === "Z" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionZ ); |
||
| 1053 | |||
| 1054 | scope.object.quaternion.copy( quaternionXYZ ); |
||
| 1055 | |||
| 1056 | } else if ( scope.space === "world" ) { |
||
| 1057 | |||
| 1058 | rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) ); |
||
| 1059 | offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) ); |
||
| 1060 | |||
| 1061 | tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) ); |
||
| 1062 | |||
| 1063 | if ( scope.rotationSnap !== null ) { |
||
| 1064 | |||
| 1065 | quaternionX.setFromAxisAngle( unitX, Math.round( ( rotation.x - offsetRotation.x ) / scope.rotationSnap ) * scope.rotationSnap ); |
||
| 1066 | quaternionY.setFromAxisAngle( unitY, Math.round( ( rotation.y - offsetRotation.y ) / scope.rotationSnap ) * scope.rotationSnap ); |
||
| 1067 | quaternionZ.setFromAxisAngle( unitZ, Math.round( ( rotation.z - offsetRotation.z ) / scope.rotationSnap ) * scope.rotationSnap ); |
||
| 1068 | |||
| 1069 | } else { |
||
| 1070 | |||
| 1071 | quaternionX.setFromAxisAngle( unitX, rotation.x - offsetRotation.x ); |
||
| 1072 | quaternionY.setFromAxisAngle( unitY, rotation.y - offsetRotation.y ); |
||
| 1073 | quaternionZ.setFromAxisAngle( unitZ, rotation.z - offsetRotation.z ); |
||
| 1074 | |||
| 1075 | } |
||
| 1076 | |||
| 1077 | quaternionXYZ.setFromRotationMatrix( worldRotationMatrix ); |
||
| 1078 | |||
| 1079 | if ( scope.axis === "X" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX ); |
||
| 1080 | if ( scope.axis === "Y" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionY ); |
||
| 1081 | if ( scope.axis === "Z" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionZ ); |
||
| 1082 | |||
| 1083 | tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ ); |
||
| 1084 | |||
| 1085 | scope.object.quaternion.copy( tempQuaternion ); |
||
| 1086 | |||
| 1087 | } |
||
| 1088 | |||
| 1089 | } |
||
| 1090 | |||
| 1091 | scope.update(); |
||
| 1092 | scope.dispatchEvent( changeEvent ); |
||
| 1093 | scope.dispatchEvent( objectChangeEvent ); |
||
| 1094 | |||
| 1095 | } |
||
| 1096 | |||
| 1097 | function onPointerUp( event ) { |
||
| 1098 | |||
| 1099 | if ( event.button !== undefined && event.button !== 0 ) return; |
||
| 1100 | |||
| 1101 | if ( _dragging && ( scope.axis !== null ) ) { |
||
| 1102 | |||
| 1103 | mouseUpEvent.mode = _mode; |
||
| 1104 | scope.dispatchEvent( mouseUpEvent ) |
||
| 1105 | |||
| 1106 | } |
||
| 1107 | |||
| 1108 | _dragging = false; |
||
| 1109 | onPointerHover( event ); |
||
| 1110 | |||
| 1111 | } |
||
| 1112 | |||
| 1113 | function intersectObjects( pointer, objects ) { |
||
| 1114 | |||
| 1115 | var rect = domElement.getBoundingClientRect(); |
||
| 1116 | var x = ( pointer.clientX - rect.left ) / rect.width; |
||
| 1117 | var y = ( pointer.clientY - rect.top ) / rect.height; |
||
| 1118 | |||
| 1119 | pointerVector.set( ( x * 2 ) - 1, - ( y * 2 ) + 1 ); |
||
| 1120 | ray.setFromCamera( pointerVector, camera ); |
||
| 1121 | |||
| 1122 | var intersections = ray.intersectObjects( objects, true ); |
||
| 1123 | return intersections[ 0 ] ? intersections[ 0 ] : false; |
||
| 1124 | |||
| 1125 | } |
||
| 1126 | |||
| 1127 | }; |
||
| 1128 | |||
| 1132 | }() ); |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.